﻿//模板
var menuTemplate = "<ul>" +
                                "{for p in Rows}" +
                                    "{if p.Menu_Leaf=='0'}" +
                                     "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"loadCustomMenu('${p.User_Code}','${p.Menu_ID}',1);\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{else}" +
                                    "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"openPanelWithMenu('${p.Menu_ID}');\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{/if}" +
                               "{/for}" +
                               "<li class=\"floatleft menureturn\"><span onclick=\"loadCustomMenu('${Rows[0].User_Code}','0',0);\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "返回上级</div>" +
                                "</span></li>" +
                            "</ul>";

//模板
var menuTemplateno = "<ul>" +
                                "{for p in Rows}" +
                                    "{if p.Menu_Leaf=='0'}" +
                                     "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"loadCustomMenu('${p.User_Code}','${p.Menu_ID}',1);\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{else}" +
                                    "<li class=\"floatleft ${p.CustomMenuCss}\"><span onclick=\"openPanelWithMenu('${p.Menu_ID}');\">" +
                                        "<div class=\"menutop\">" +
                                        "</div>" +
                                        "<div class=\"menubottom\">" +
                                        "${p.Menu_Title}</div>" +
                                      "</span></li>" +
                                    "{/if}" +
                               "{/for}" +
                            "</ul>";


var hashTableByMenu = new HashTable();
//地区html代码生成
function loadCustomMenu(userCode, menuParentId, type) {
    if (!hashTableByMenu.ContainsKey(menuParentId)) {
        function OnSuccess(result) {
            if (result.Rows != null) {
                $("#customMenu").html('<img src="res/images/framework/loading.gif" />');
                if (type == 0) {
                    html = TrimPath.parseTemplate(menuTemplateno).process(result);
                }
                else {
                    html = TrimPath.parseTemplate(menuTemplate).process(result);
                }
                $("#customMenu").html(html);
                hashTableByMenu.Add(menuParentId, html);
                $("#customMenu").css('display', 'none');
                if (type == 0) {
                    $("#customMenu").fadeIn("fast");
                }
                else {
                    $("#customMenu").fadeIn("slow");
                }
            }
        }
        $.ajax({ type: "POST", url: "Data/MainPageCustom.ashx", data: "m=GetCustomMenu&usercode=" + userCode + "&menuparentid=" + menuParentId, dataType: "json", success: OnSuccess });
    }
    else {
        var result = hashTableByMenu.GetValue(menuParentId);

        $("#customMenu").html(result);
        $("#customMenu").css('display', 'none');
        if (type == 0) {
            $("#customMenu").fadeIn("fast");
        }
        else {
            $("#customMenu").fadeIn("slow");
        }
    }
}



//模板
var rightTemplateByZjzx = "<ul>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].MarketCollectCount}</span>个市场确认划转货款信息<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxMarketCollect','市场已划转，等待总公司回笼信息','Remind/marketcollected.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Pay_Count} </span>条尚未处理的货款申请<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('015001','货款下拨','Business/AllocateMoney.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Collect_Count}</span>条尚未回笼的划转明细<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxCollect','未回笼的资金上划明细','Remind/PadBilling.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].BadContract_Count} </span>条尚未处理的违约信息<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxBadContract','未处理的合同违约列表','Remind/BadContracting.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closing} </span>条合同即将到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closed} </span>条合同已经到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Market_Confrim} </span>条合同直属库粮食出库完成，交易市场尚未确认<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('ZjzxMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_MarketandOrg_Confrim} </span>条合同直属库粮食实际出库数量与交易市场确认数量不一致<span><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">详情</a></span></li>" +
                           "</ul>";

//模板
var rightTemplateByFgs = "<ul>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Pay_Count} </span>条尚未处理的货款申请<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('011005');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Pay_Count2}</span>条尚未处理的多退少补<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('011006');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].PayBilling_Count} </span>条尚未审核的出库确认单等待审核<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('010005');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].RequetingCount} </span>条出库通知单已经出库确认，尚未申请资金<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('RequetingCount','确认出库后未申请资金的合同','Remind/RequestMoneying.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closing} </span>条合同即将到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closed} </span>条合同已经到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Market_Confrim} </span>条合同直属库粮食出库完成，交易市场尚未确认<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_MarketandOrg_Confrim} </span>条合同直属库粮食实际出库数量与交易市场确认数量不一致<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">详情</a></span></li>" +
                           "</ul>";

//模板
var rightTemplateByZsk = "<ul>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].PayBilling_Count} </span>条出库通知单尚未全部出库<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('023005');\">详情</a></span></li>" +
                                //"<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_NotPayBillCount}</span>条合同出库通知单未录入完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('009001');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].RequetingCount} </span>条出库通知单已经出库确认，尚未申请资金<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('023009');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closing} </span>条合同即将到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closed} </span>条合同已经到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].OverRuleNum} </span>条拨付申请已经被退回<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxOverRule','已退回资金申请列表','Remind/OverRuleRequestMoneyDetailed.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].CountPayMone} </span>条尚未查看的拨付资金<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','未查看的资金拨付详情','Remind/AllocateMoney.aspx');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Market_Confrim} </span>条合同直属库粮食出库完成，交易市场尚未确认<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('ZjzxMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_MarketandOrg_Confrim} </span>条合同直属库粮食实际出库数量与交易市场确认数量不一致<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">详情</a></span></li>" +
                           "</ul>";

//模板
var rightTemplateByZskKz = "<ul>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Pay_Count} </span>条尚未处理的货款申请<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('011007');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Pay_Count2}</span>条尚未处理的多退少补<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithMenu('011008');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closing} </span>条合同即将到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracting','即将到期的合同列表','Remind/Contracting.aspx?type=0');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Closed} </span>条合同已经到期，尚未交割完成<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('zjzxContracted','已经到期的合同列表','Remind/Contracting.aspx?type=1');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_Market_Confrim} </span>条合同直属库粮食出库完成，交易市场尚未确认<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('ZjzxMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=100');\">详情</a></span></li>" +
                                "<li>有<span style=\"color: #f00; font-size: 14px;\"> ${Rows[0].Contract_MarketandOrg_Confrim} </span>条合同直属库粮食实际出库数量与交易市场确认数量不一致<span name=\"detail\"><a harf=\"javascript:void(0);\" onclick=\"openPanelWithOutMenu('FgsMarket_Confirm','品种详情列表','Remind/ContractConfirmStatusList.aspx?status=200');\">详情</a></span></li>" +
                           "</ul>";

function loadRight(orgCode, m, templateStr) {
    $("#likbg").html('<img src="res/images/framework/loading.gif" />');
    function OnSuccess(result) {
        if (result.Rows != null) {
            $("#likbg").html('<img src="res/images/framework/loading.gif" />');

            html = TrimPath.parseTemplate(templateStr).process(result);

            $("#likbg").html(html);
        }
    }
    $.ajax({ type: "POST", url: "Data/MainPageCustom.ashx", data: "m=" + m + "&orgcode=" + orgCode, dataType: "json", success: OnSuccess });
}

function initRight() {
    var orgCode = $('#hfdOrgCode').val();
    var roleSign = $('#hfdRoleSign').val();
    var orgType = $('#hfdOrgType').val();
    var userMemo = $('#hfdUserMemo').val();
    //alert(roleSign);
    if (roleSign == 'zjzx') {
        loadRight(orgCode, 'GetRemindZjzx', rightTemplateByZjzx);
    }
    else if (roleSign == 'fgs') {
        loadRight(orgCode, 'GetRemindFgs', rightTemplateByFgs);
    }
    else if (roleSign == 'zskkz') {
        loadRight(orgCode, 'GetRemindZsk', rightTemplateByZskKz);
    }
    else if (roleSign == 'zsk') {
        loadRight(orgCode, 'GetRemindZsk', rightTemplateByZsk);
    }
    else if (orgCode == 'SA0100010000001') {
        loadRight(orgCode, 'GetRemindZjzx', rightTemplateByZjzx);
        document.getElementsByName('detail');
        $("span[name='detail']").css("display", 'none');
    }
    else if (orgType == 'FGS') {
        loadRight(orgCode, 'GetRemindFgs', rightTemplateByFgs);
        document.getElementsByName('detail');
        $("span[name='detail']").css("display", 'none');
    }
    else if (orgType == 'ZSK') {
        loadRight(orgCode, 'GetRemindZsk', rightTemplateByZsk);
        document.getElementsByName('detail');
        $("span[name='detail']").css("display", 'none');
    }
    else {
        loadRight(orgCode, 'GetRemindZjzx', rightTemplateByZjzx);
        document.getElementsByName('detail');
        $("span[name='detail']").css("display", 'none');
    }

    if (userMemo == 'CX') {
        $("span[name='detail']").css("display", 'none');
    }
    //setTimeout(initRight, 1800000);
}

$(document).ready(function() {
    loadCustomMenu($('#hfdUserCode').val(), '0', 0);
    initRight();
});